<%@page contentType="application/json" pageEncoding="UTF-8"%><%
    String callback = request.getParameter("callback");

    // Se inicia el callback
    out.print(callback + "({");

    String find = request.getParameter("sfind") + "%";
    java.util.List<satk.objetos.Categoria> cats = new satk.database.ManagerCategoria().findCategoria(find, 10);

    String numResult = String.format("\"totalResultsCount\":%d ", cats.size());
    out.print(numResult);

    out.print(", \"categorias\":[");

    int ctrlN = 0;
    for (satk.objetos.Categoria c : cats) {
        String a = String.format("{\"id\": \"%s\", \"name\": \"%s\", \"sigla\": \"%s\"}",
                c.getIdentificador(), c.getNombre(), c.getSiglas());
        if (ctrlN > 0) {
            a = "," + a;
        }
        out.print(a);
        ctrlN++;
    }
    out.print("] "); // Termina categorias

    // Termina el callback
    out.print("});");
%>